package com.retail.lottery.colalottery.enums;

/**
 * 错误码命名方式五位数长度
 * 第一位大业务+二级业务+三级业务+2位错误码
 * 全局异常定义
 *
 * @author alan
 */
public enum CommonEnum {
    SUCCESS(true, 200, "请求成功!"),
    ERROR(false, 201, "请求失败!"),
    BODY_NOT_MATCH(false, 400, "参数解析错误!"),
    SIGNATURE_NOT_MATCH(false, 401, "请求的数字签名不匹配!"),
    NOT_FOUND(false, 404, "未找到该资源!"),
    SIGN_ERROR(false, 405, "验签失败"),
    INTERNAL_SERVER_ERROR(false, 500, "服务器内部错误!"),
    SERVER_BUSY(false, 503, "服务器正忙，请稍后再试!"),
    NOT_LOGIN_ERROR(false, 403, "token失效！请重新登录！"),
    INVOKE_SERVICE_ERROR(false, 10001, "调用服务失败！"),
    GET_JSAPI_TICKET_FAIL(false, -1, "获取微信服务号JSAPI_TICKET失败"),
    GET_ACCESS_TOKEN_FAIL(false, -1, "获取ACCESS_TOKEN失败"),
    FAILED_TO_CREATE_ENTERPRISE_MASS_DISTRIBUTION(false, 100001, "创建企业群发失败"),
    FAILED_TO_SEND_APPLICATION_MESSAGE(false, 100003, "发送应用消息失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_UPLOAD(false, 100008, "上传素材失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_USERID_TO_OPEN_USERID(false, 100009, "userid换三方userid失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_UNIONID_TO_EXTERNAL_USERID(false, 100010, "unionId转换为第三方externalUserid失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_GET_NEW_EXTERNAL_USERID(false, 100011, "external_userid转换失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_SEND_MESSAGE(false, 100016, "消息推送失败"),
    DATA_FORMAT_FALSE(false, 50006, "日期格式不正确"),
    EXCEL_FAIL(false, 80001, "excel解析失败"),
    EXCEL_NULL(false, 80002, "上传文件为空"),
    GIFT_NOT_ON(false, 80003, "礼品剩余库存为0无法上架"),
    NOT_ALLOW_EDIT(false, 80004, "上架不允许编辑"),
    STORE_GIFT_EXIST(false, 80005, "该门店礼品已存在"),
    GIFT_NAME_TOO_LONG(false, 80007, "礼品名称不能大于100个字符"),
    GIFT_STOCK_LENGTH_LIMIT(false, 80008, "总库存的长度超过了限制"),
    TOO_LONG(false, 80009, "长度不能超过100"),
    TIME_LIMIT(false, 81000, "时间差超过了一年"),
    TIME_NOT_FUTURE_TIME(false, 81001, "购买时间不能选择未来时间"),
    PICTURE_TYPE_LIMIT(false, 81003, "礼品图片仅支持JPG,PNG格式"),
    STOCK_REDUCE(false, 81004, "库存不足"),
    ERR_00000000815(false, 81005, "请上传文件"),
    NAME_EXIST(false, 81006, "礼品名称重复"),
    GIFT_NAME_EXIST(false, 81007, "已存在该礼品"),
    GIFT_NAME_NOT_NULL(false, 81008, "礼品名称不能为空"),
    PLEASE_INPUT_DATA(false, 81009, "请输入必填项"),
    REMARK_TOO_LONG(false, 81010, "备注长度过长"),
    TIME_ERROR(false, 81011, "开始时间不能在结束时间之后"),
    GIFT_AMOUNT_NOT_NULL(false, 81012, "礼品金额不能为空"),
    EXPRESS_TOO_MUCH(false, 81013, "快递信息不能超过3个"),
    EXPRESS_NUM_SAME(false, 81013, "快递单号重复"),
    PROCESS_NOT_NULL(false, 82001, "审批记录不存在"),
    UPLOAD_FILE_FAIL(false,82002,"文件上传失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_UPLOAD_ATTACHMENT(false, 900001, "上传附件资源失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_ADD_MOMENT_TASK(false, 1000001, "发送朋友圈任务失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_GET_MOMENT_TASK_RESULT(false, 1000002, "获取朋友圈结果失败"),
    FAILED_TO_OBTAIN_THE_EXECUTION_RESULT_OF_GET_MOMENT_TASK(false, 1000003, "获取朋友圈结果失败"),
    FAILED_TO_CANCEL_GROUP_MSG_SEND(false, 2000001, "停止企业群发失败"),
    FAILED_TO_CANCEL_MOMENT_TASK(false, 2000002, "停止发表企业朋友圈失败"),
    ERR_ENUM_EMPTY_MOBILE(false,83001,"提现失败：手机号为空"),
    SIGN_FAIL(false, 405, "SIGN ERROR"),

    ;

    private final Integer resultCode;
    private final String resultMsg;
    private final Boolean flag;

    CommonEnum(Boolean flag, Integer resultCode, String resultMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.flag = flag;
    }

    public Boolean getFlag() {
        return flag;
    }

    public Integer getResultCode() {
        return resultCode;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public static CommonEnum getCommonEnum(Integer code) {
        for (CommonEnum commonEnum : CommonEnum.values()) {
            if (commonEnum.getResultCode().equals(code)) {
                return commonEnum;
            }
        }
        return ERROR;
    }

}
